//
//  TreeNode.swift
//  Tree
//
//  Created by Toj on 8/1/21.
//

import Cocoa

class TreeNode {
    var leftTree: TreeNode?
    var rightTree: TreeNode?
    
    var name: String?
    var value: Int?
    
    deinit {
        print(name ?? "")
    }
}

func initTree() -> TreeNode {
    let treeA: TreeNode = TreeNode()
    treeA.name = "A"
    treeA.value = 10
    
    let treeB: TreeNode = TreeNode()
    treeB.name = "B"
    treeB.value = 6
    let treeF: TreeNode = TreeNode()
    treeF.name = "F"
    treeF.value = 14

    let treeC: TreeNode = TreeNode()
    treeC.name = "C"
    treeC.value = 4
    let treeD: TreeNode = TreeNode()
    treeD.name = "D"
    treeD.value = 8

    let treeE: TreeNode = TreeNode()
    treeE.name = "E"
    treeE.value = 12
    let treeG: TreeNode = TreeNode()
    treeG.name = "G"
    treeG.value = 16

    treeA.leftTree = treeB
    treeA.rightTree = treeF

    treeB.leftTree = treeC
    treeB.rightTree = treeD

    treeF.leftTree = treeE
    treeF.rightTree = treeG
    
    return treeA
}
